package com.xplay.xpocker.room.mahjong.dto;

import com.xplay.xpocker.constant.ConstantDict;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public enum WzRuleEnum {
    HSZ(RuleConstant.HSZ, "换三张"),
    QSHS("QSHS", "前三后四"),
    YJTU("YJTU", "幺鸡替用"),
    MP("MP", "买牌"),
    YHJB("YHJB", "硬胡加倍"),
    MFBH("MFBH", "满番必胡"),
    YTDD("YTDD", "一贪到底"),
    GSJFKH("GSJFKH", "过手加番可胡"),
    XHBZ("XHBZ", "小胡不走");

    static {
        RULE_CACHE = Arrays.stream(WzRuleEnum.values()).collect(Collectors.toMap(WzRuleEnum::getCode, Function.identity()));
    }

    public static final Map<String, WzRuleEnum> RULE_CACHE;
    public String code;
    public String name;

    public static WzRuleEnum of(String type) {
        return RULE_CACHE.get(type);
    }

    /**
     * 校验规则是否包含某个规则
     *
     * @param rules
     * @param ruleEnum
     * @return
     */

    public static boolean contain(List<String> rules, WzRuleEnum ruleEnum) {
        if (rules == null || rules.size() == 0) {
            return false;
        }
        return rules.stream().anyMatch(item -> RULE_CACHE.get(item) != null);
    }

    WzRuleEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
